Pick Gradle distribution based on client JVM version#7534
Merged
Conversation
The Tooling API daemon defaults to the same JVM as the client, so the hardcoded 8.12 fallback fails on Java 24+ and Java 25+. Map the running Java version to the lowest Gradle distribution that can host its daemon (8.12 for <=23, 8.14.3 for 24, 9.1.0 for 25+) instead.
timtebeek
commented
Apr 30, 2026
8.14.3 supports Java 8 through 24, so a separate 8.12 baseline isn't needed. Only Java 25+ still requires the Gradle 9 line.
Member
Author
|
Making this change now, as we're seeing downstream test failures when running on Java 25 |
shanman190
approved these changes
Apr 30, 2026
2 tasks
timtebeek
added a commit
that referenced
this pull request
May 1, 2026
8.14.4 has a Kotlin DSL regression that breaks `plugins {}` blocks with
local `val` declarations (16 :rewrite-gradle:test failures); 8.14.3 has
no such regression and matches the pre-#7534 default for Java < 25.
timtebeek
added a commit
that referenced
this pull request
May 1, 2026
* Revert JVM-based Gradle distribution picker, pin to 8.14.4 Replaces the per-JVM-version dispatch added in #7534 with a single hardcoded Gradle distribution. Removes the now-unused helpers and their test. * Replace -b with rootProject.buildFileName for Gradle 9 support Gradle 9 dropped -b. When the caller passes a build file at a non-conventional location, write a temporary settings.gradle with only rootProject.buildFileName, deleting it in the same finally block as the init script. * Skip settings.gradle existence check when build file is conventional * Gate the settings.gradle path on Gradle 9+, keep -b for Gradle 8 Determine the Gradle version from the explicit useGradleVersion call or from gradle-wrapper.properties when useBuildDistribution is in play. Existing tests on Gradle 8 keep using -b. The settings.gradle path now writes with CREATE_NEW so it can never overwrite a user-supplied file, and the cleanup deletes only files we actually wrote (settingsWritten flag). * Inline settings.gradle write next to path determination Move the Files.write call up into the same block that decides we need a temporary settings file, and collapse the two nested try/finally blocks into one outer finally that handles both init and settings cleanup. settingsWritten still gates the delete so a race-introduced or pre-existing user file is never touched. * Simplify version selection and collapse outer try/finally * Pin Tooling-API client default to Gradle 8.14.3 8.14.4 has a Kotlin DSL regression that breaks `plugins {}` blocks with local `val` declarations (16 :rewrite-gradle:test failures); 8.14.3 has no such regression and matches the pre-#7534 default for Java < 25.
Contributor
|
nice work @timtebeek |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
OpenRewriteModelBuilderpreviously hardcoded a fallback Gradle version of8.12, which can't host its daemon on Java 24+ or Java 25+. Projects without agradle-wrapper.propertiestherefore fail to build their tooling model on newer JDKs.defaultGradleVersion(int javaFeatureVersion)that maps the running Java version to the lowest compatible distribution per the Gradle compatibility matrix:8.12(unchanged)8.14.39.1.0java.specification.version(Java 8 compatible); the existingorg.openrewrite.test.gradleVersionsystem-property override and wrapper-detection paths are untouched.OpenRewriteModelBuilderTestto lock in the version mapping.Notes / open questions
8.12, but worth flagging.8.14.3/9.1.0should be parameterized (e.g. read from a properties file) so we can advance them without code changes — happy to follow up if preferred.Test plan
./gradlew :rewrite-gradle-tooling-model:model:test --tests "org.openrewrite.gradle.toolingapi.OpenRewriteModelBuilderTest"passes locallyOpenRewriteModelBuilder.forProjectDirectoryfrom a project without a wrapper, on Java 25, and confirm the daemon starts